package com.yanqu.road.entity.wingroom.config.regioncoords;

import com.yanqu.road.entity.wingroom.RegionBlock;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zfr
 * @date ：2022/2/15 17:13
 */
public abstract class BaseRegionCoords {
    protected int regionId;
    String clientRegionStr = "";
    private List<RegionBlock> regionCoords = new ArrayList<>();

    public abstract void buildClientRegionCoordsStr();

    public void putCoords(int regionId) {
        this.regionId = regionId;
        regionCoords = new ArrayList<>();
        buildClientRegionCoordsStr();
        String[] coordsArray = clientRegionStr.split(",");
        for (String coords : coordsArray) {
            String[] coordsPar = coords.split(":");
            int yCoords = Integer.parseInt(coordsPar[0]);
            String xCoordsArray = coordsPar[1];
            for (int i = 0; i < xCoordsArray.length(); i++) {
                int xCoordsValue = Integer.parseInt(String.valueOf(xCoordsArray.charAt(i)));
                if (xCoordsValue == 0) {
                    regionCoords.add(new RegionBlock(i, yCoords));
                }
            }
        }
    }

    public List<RegionBlock> getRegionCoords() {
        return regionCoords;
    }
}
